﻿using System;
using System.Data;
using System.Xml;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Soft000.Config;
using System.Collections;

namespace Soft000.Data
{
    /// <summary>
    /// 数据库操作辅助类
    /// </summary>
    public class DbHelper
    {
        #region 私有变量
        /// <summary>
        /// 数据连接字符串
        /// </summary>
        protected static string m_connectionstring = null;

        /// <summary>
        /// DbProviderFactory实例
        /// </summary>
        private static DbProviderFactory m_factory = null;
        /// <summary>
        /// 数据接口
        /// </summary>
        private static IDbProvider m_provider = null;
        // Hashtable to store cached parameters
        private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
        /// <summary>
        /// 互斥对像
        /// </summary>
        private static object lockerHelper = new object();
        #endregion

        #region 属性
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (m_connectionstring == null)
                {
                    m_connectionstring = BaseConfigs.GetDBConnectString;
                }
                return m_connectionstring;
            }
            set
            {
                m_connectionstring = value;
            }
        }
        /// <summary>
        /// IDbProvider接口
        /// </summary>
        public static IDbProvider Provider
        {
            get
            {
                if (m_provider == null)
                {
                    lock (lockerHelper)
                    {
                        if (m_provider == null)
                        {
                            try
                            {
                                switch (BaseConfigs.GetDbType)
                                {
                                    case 1:
                                        m_provider = new SqlServerProvider();
                                        break;
                                    case 2:
                                        m_provider = new AccessProvider();
                                        break;
                                }
                            }
                            catch
                            {
                                throw new Exception("请检查DB.config中Dbtype节点数据库类型是否正确，例如：SqlServer、Access、MySql.");
                            }
                        }
                    }
                }
                return m_provider;
            }
        }
        /// <summary>
        /// DbFactory实例
        /// </summary>
        public static DbProviderFactory Factory
        {
            get
            {
                if (m_factory == null)
                {
                    m_factory = Provider.Instance();
                }
                return m_factory;
            }
        }
        /// <summary>
        /// 刷新数库提供者
        /// </summary>
        public static void ResetDbProvider()
        {
            BaseConfigs.ResetConfig();
            m_connectionstring = null;
            m_factory = null;
            m_provider = null;
        }
        #endregion

        #region 生成参数

        public static DbParameter MakeInParam(string ParamName, DbType DbType, int Size, object Value)
        {
            return MakeParam(ParamName, DbType, Size, ParameterDirection.Input, Value);
        }

        public static DbParameter MakeOutParam(string ParamName, DbType DbType, int Size)
        {
            return MakeParam(ParamName, DbType, Size, ParameterDirection.Output, null);
        }

        public static DbParameter MakeParam(string ParamName, DbType DbType, Int32 Size, ParameterDirection Direction, object Value)
        {
            DbParameter param;

            param = Provider.MakeParam(ParamName, DbType, Size);

            param.Direction = Direction;
            if (!(Direction == ParameterDirection.Output && Value == null))
                param.Value = Value;

            return param;
        }

        #endregion 生成参数结束

        #region 执行SQL命令返回所影响的行
        /// <summary>
        /// 执行SQL语句返回所影响的行
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">要执行的SQL命令</param>
        /// <param name="commandParameters">参数</param>
        /// <returns>返回所影响的行</returns>
        public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();

            using (DbConnection conn = Factory.CreateConnection())
            {
                try
                {
                    conn.ConnectionString = connectionString;
                    PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                    int val = cmd.ExecuteNonQuery();
                    return val;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Parameters.Clear();
                    conn.Close();
                }

            }
        }
        public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            return ExecuteNonQuery(ConnectionString, cmdType, cmdText, commandParameters);
        }
        /// <summary>
        /// 执行SQL命令，返回所影响的行
        /// </summary>
        /// <param name="connection">数据连接对像</param>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回所影响的行</returns>
        public static int ExecuteNonQuery(DbConnection connection, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();

            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            int val = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            return val;
        }
        /// <summary>
        /// 执行SQL命令，返回所影响的行
        /// </summary>
        /// <param name="trans">事务对象</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static int ExecuteNonQuery(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            if (trans == null) throw new ArgumentNullException("DbTransaction is null");
            if (trans.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");

            DbCommand cmd = Factory.CreateCommand();
            try
            {
                PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
                int val = cmd.ExecuteNonQuery();

                return val;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
            }
        }
        #endregion

        #region 执行SQL命令返回DataSet数据集
        /// <summary>
        /// 执行SQL命令返回DataSet数据集
        /// </summary>
        /// <param name="connectionString">联接字符串</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">命令参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();

            using (DbConnection conn = Factory.CreateConnection())
            {
                try
                {
                    conn.ConnectionString = connectionString;
                    PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                    DbDataAdapter adp = Factory.CreateDataAdapter();
                    adp.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    adp.Fill(ds);
                    return ds;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Parameters.Clear();
                    conn.Close();
                }

            }

        }
        /// <summary>
        /// 执行SQL命令返回DataSet数据集
        /// </summary>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">命令参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            return ExecuteDataSet(ConnectionString, cmdType, cmdText, commandParameters);
        }
        /// <summary>
        /// 执行SQL命令返回DataSet数据集
        /// </summary>
        /// <param name="connection">数据连接对像</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(DbConnection connection, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();
            try
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                DbDataAdapter adp = Factory.CreateDataAdapter();
                adp.SelectCommand = cmd;
                DataSet ds = new DataSet();
                adp.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
            }

        }
        /// <summary>
        /// 执行SQL命令返回DataSet数据集
        /// </summary>
        /// <param name="trans">事务对像</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            if (trans == null) throw new ArgumentNullException("DbTransaction is null");
            if (trans.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
            DbCommand cmd = Factory.CreateCommand();
            try
            {
                PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
                DataSet ds = new DataSet();
                DbDataAdapter adp = Factory.CreateDataAdapter();
                adp.SelectCommand = cmd;
                adp.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
            }
        }

        /// <summary>
        /// 通用分页函数，对于数据量较大的建义用SQL存储过程
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="curPage">当前页</param>
        /// <param name="pageSize">每页显示的记录数</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns></returns>
        public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, int curPage, int pageSize, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();

            using (DbConnection conn = Factory.CreateConnection())
            {
                try
                {
                    conn.ConnectionString = connectionString;
                    PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                    DbDataAdapter adp = Factory.CreateDataAdapter();
                    adp.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    if (curPage < 1)
                        curPage = 1;
                    adp.Fill(ds, (curPage - 1) * pageSize, pageSize, "table0");

                    return ds;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Parameters.Clear();
                    conn.Close();
                }
            }
        }
        /// <summary>
        ///  通用分页函数，对于数据量较大的建义用SQL存储过程
        /// </summary>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="curPage">当前页</param>
        /// <param name="pageSize">每页显示的记录数</param>
        /// <param name="commandParameters">SQL命令参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, int curPage, int pageSize, params DbParameter[] commandParameters)
        {
            return ExecuteDataSet(ConnectionString, cmdType, cmdText, curPage, pageSize, commandParameters);
        }
        /// <summary>
        /// 通用分页函数，对于数据量较大的建义用SQL存储过程
        /// </summary>
        /// <param name="connection">数据库连接对象</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="curPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(DbConnection connection, CommandType cmdType, string cmdText, int curPage, int pageSize, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();
            try
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                DbDataAdapter adp = Factory.CreateDataAdapter();
                adp.SelectCommand = cmd;
                DataSet ds = new DataSet();
                if (curPage < 1)
                    curPage = 1;
                adp.Fill(ds, (curPage - 1) * pageSize, pageSize, "table0");

                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
            }
        }
        /// <summary>
        /// 通用分页函数，对于数据量较大的建义用SQL存储过程
        /// </summary>
        /// <param name="trans">事务对像</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="curPage">当前页</param>
        /// <param name="pageSize">每页显示的记录数</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回DataSet数据集</returns>
        public static DataSet ExecuteDataSet(DbTransaction trans, CommandType cmdType, string cmdText, int curPage, int pageSize, params DbParameter[] commandParameters)
        {
            if (trans == null) throw new ArgumentNullException("DbTransaction is null");
            if (trans.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
            DbCommand cmd = Factory.CreateCommand();
            try
            {
                PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
                DataSet ds = new DataSet();
                DbDataAdapter adp = Factory.CreateDataAdapter();
                if (curPage < 1)
                    curPage = 1;
                adp.Fill(ds, (curPage - 1) * pageSize, pageSize, "table0");


                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
            }
        }
        #endregion

        #region 执行SQL命令返回DataReader对像
        //如果创建了 SqlDataReader 并将 CommandBehavior 设置为 CloseConnection，则关闭 SqlDataReader 会自动关闭此连接。
        /// <summary>
        /// 执行SQL命令返回DataReader对像,使用该对像注意资源的释放
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回DataReader</returns>
        public static DbDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            DbCommand cmd = Factory.CreateCommand();
            DbConnection conn = Factory.CreateConnection();
            conn.ConnectionString = connectionString;

            try
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                DbDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return rdr;
            }
            catch
            {
                conn.Close();
                throw;
            }
        }
        /// <summary>
        /// 执行SQL命令返回DataReader对像,使用该对像注意资源的释放
        /// </summary>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回DataReader</returns>
        public static DbDataReader ExecuteReader(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            return ExecuteReader(ConnectionString, cmdType, cmdText, commandParameters);
        }
        #endregion

        #region 执行SQL语句,返回结果集中第一行第一列的值
        /// <summary>
        /// 执行SQL语句,返回结果集中第一行第一列的值
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">SQL参数</param>
        /// <returns>返回结果集中第一行第一列的值</returns>
        public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            DbCommand cmd = Factory.CreateCommand();

            using (DbConnection connection =Factory.CreateConnection())
            {
                try
                {
                    connection.ConnectionString = connectionString;
                    PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                    object val = cmd.ExecuteScalar();

                    return val;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Parameters.Clear();
                    connection.Close();
                }
            }
        }
        /// <summary>
        /// 执行SQL语句,返回结果集中第一行第一列的值
        /// </summary>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">参数</param>
        /// <returns>返回结果集中第一行第一列的值</returns>
        public static object ExecuteScalar(CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {
            return ExecuteScalar(ConnectionString, cmdType, cmdText, commandParameters);
        }
        /// <summary>
        /// 执行SQL语句,返回结果集中第一行第一列的值
        /// </summary>
        /// <param name="connection">数据连接对像</param>
        /// <param name="cmdType">SQL命令类型</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="commandParameters">参数</param>
        /// <returns>返回结果集中第一行第一列的值</returns>
        public static object ExecuteScalar(DbConnection connection, CommandType cmdType, string cmdText, params DbParameter[] commandParameters)
        {

            DbCommand cmd = Factory.CreateCommand();
            try
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                object val = cmd.ExecuteScalar();

                return val;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Parameters.Clear();
            }
        }
        #endregion

        #region 其它

        /// <summary>
        /// Prepare a command for execution
        /// </summary>
        /// <param name="cmd">SqlCommand object</param>
        /// <param name="conn">SqlConnection object</param>
        /// <param name="trans">SqlTransaction object</param>
        /// <param name="cmdType">Cmd type e.g. stored procedure or text</param>
        /// <param name="cmdText">Command text, e.g. Select * from Products</param>
        /// <param name="cmdParms">SqlParameters to use in the command</param>
        private static void PrepareCommand(DbCommand cmd, DbConnection conn, DbTransaction trans, CommandType cmdType, string cmdText, DbParameter[] cmdParms)
        {

            if (conn.State != ConnectionState.Open)
                conn.Open();

            cmd.Connection = conn;
            cmd.CommandText = cmdText;

            if (trans != null)
                cmd.Transaction = trans;

            cmd.CommandType = cmdType;

            if (cmdParms != null)
            {
                foreach (DbParameter parm in cmdParms)
                    cmd.Parameters.Add(parm);
            }
        }
        #endregion

        #region 通用添加,修改，删除方法
        ///// <summary>
        ///// 添加
        ///// </summary>
        ///// <param name="model">数据实体类，各属性名必须与数据库里的字段名一致</param>
        ///// <param name="tableName">表名</param>
        ///// <returns></returns>
        //public static bool Insert(Object model, string tableName)
        //{
        //    string strSQL = "insert into [" + tableName + "](";
        //    System.Type t = model.GetType();
        //    string strParam = "";
        //    string strParamName = "";
        //    SqlParameter[] parms;
        //    System.Reflection.PropertyInfo[] pt = t.GetProperties();
        //    int count = 0;
        //    ArrayList arrIden = GetIdentity(tableName);
        //    parms = new SqlParameter[pt.Length - arrIden.Count];
        //    foreach (System.Reflection.PropertyInfo p in pt)
        //    {
        //        if (!IsIdentity(p.Name, arrIden))
        //        {
        //            strSQL = strSQL + "[" + p.Name + "],";
        //            strParam += "@" + p.Name + ",";
        //            Object obj = p.GetValue(model, null);
        //            parms[count++] = new SqlParameter("@" + p.Name, obj);
        //        }
        //    }
        //    strSQL = strSQL.Substring(0, strSQL.Length - 1) + ")" + " values(" + strParam.Substring(0, strParam.Length - 1) + ")";
        //    return SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, strSQL, parms) == 1;
        //}
        ///// <summary>
        ///// 修改
        ///// </summary>
        ///// <param name="model">数据实体类，各属性名必须与数据库里的字段名一致</param>
        ///// <param name="tableName">表名</param>
        ///// <returns></returns>
        //public static bool Update(object model, String tableName)
        //{
        //    string strSQL = "Update [" + tableName + "] set ";
        //    ArrayList keys = new ArrayList();
        //    DataSet ds = new DataSet();
        //    Type t = model.GetType();
        //    string strParam = "";
        //    SqlParameter[] parms;
        //    System.Reflection.PropertyInfo[] pt = t.GetProperties();
        //    parms = new SqlParameter[pt.Length];
        //    int count = 0;
        //    SqlParameter[] keyparm ={
        //        new SqlParameter("@table_name",tableName)
        //    };
        //    ds = ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, "sp_pkeys", keyparm);

        //    foreach (DataRow dr in ds.Tables[0].Rows)
        //    {
        //        keys.Add(dr["COLUMN_NAME"]);
        //    }

        //    //如果没主键返回FALSE，更新失败
        //    if (keys == null || keys.Count == 0)
        //    {
        //        return false;
        //    }

        //    foreach (System.Reflection.PropertyInfo p in pt)
        //    {
        //        if (!IsPrimaryKey(p.Name, keys))
        //        {
        //            strSQL += "[" + p.Name + "]=@" + p.Name + ",";
        //            object obj = p.GetValue(model, null);
        //            parms[count++] = new SqlParameter("@" + p.Name, obj);
        //        }
        //    }
        //    strSQL = strSQL.Substring(0, strSQL.Length - 1) + " where 1=1";

        //    for (int i = 0; i < keys.Count; i++)
        //    {
        //        string strkey = keys[i].ToString().Trim();
        //        strSQL += " and " + strkey + "=@" + strkey;
        //        System.Reflection.PropertyInfo pk = t.GetProperty(strkey);
        //        parms[count++] = new SqlParameter("@" + strkey, pk.GetValue(model, null));
        //    }
        //    return ExecuteNonQuery(ConnectionString, CommandType.Text, strSQL, parms) == 1;
        //}
        //public static bool Delete(object model, string tableName)
        //{
        //    string strSQL = "Delete from [" + tableName + "] where 1=1";
        //    ArrayList keys = new ArrayList();
        //    string strParam = "";
        //    SqlParameter[] parms;
        //    Type t = model.GetType();
        //    int i = 0;

        //    System.Reflection.PropertyInfo[] pt = t.GetProperties();
        //    int count = 0;

        //    SqlParameter[] keyparm ={
        //        new SqlParameter("@table_name",tableName)
        //    };
        //    DataSet ds = ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, "sp_pkeys", keyparm);
        //    foreach (DataRow dr in ds.Tables[0].Rows)
        //    {
        //        keys.Add(dr["COLUMN_NAME"]);
        //    }
        //    parms = new SqlParameter[keys.Count];
        //    //如果没有主键，删除失败
        //    if (keys == null || keys.Count == 0)
        //        return false;
        //    foreach (System.Reflection.PropertyInfo p in pt)
        //    {
        //        if (IsPrimaryKey(p.Name, keys))
        //        {
        //            string strkey = keys[i].ToString().Trim();
        //            strSQL += " and " + strkey + "=@" + strkey;
        //            System.Reflection.PropertyInfo pk = t.GetProperty(strkey);
        //            parms[count++] = new SqlParameter("@" + strkey, pk.GetValue(model, null));
        //        }
        //    }
        //    return ExecuteNonQuery(ConnectionString, CommandType.Text, strSQL, parms) == 1;
        //}
        //private static ArrayList GetIdentity(string tableName)
        //{
        //    ArrayList arr = new ArrayList();
        //    SqlParameter[] parm ={
        //        new SqlParameter("@objname",tableName)
        //    };
        //    DataSet ds = new DataSet();
        //    ds = ExecuteDataSet(ConnectionString, CommandType.StoredProcedure, "sp_help", parm);
        //    foreach (DataRow dr in ds.Tables[2].Rows)
        //    {
        //        object obj = dr["seed"];
        //        if (Convert.IsDBNull(obj))
        //        {
        //            return arr;
        //        }
        //        arr.Add(dr["Identity"]);
        //    }
        //    return arr;
        //}
        //private static bool IsPrimaryKey(string strName, ArrayList keys)
        //{
        //    if (keys == null)
        //        return false;
        //    string strKey = "";
        //    String strLowerName = strName.Trim().ToLower();
        //    for (int i = 0; i < keys.Count; i++)
        //    {
        //        if (!(keys[i] == null))
        //        {
        //            strKey = keys[i].ToString().Trim().ToLower();
        //            if (strKey == strLowerName)
        //            {
        //                keys[i] = strName;
        //                return true;
        //            }
        //        }
        //    }
        //    return false;
        //}
        //private static bool IsIdentity(string strName, ArrayList arr)
        //{
        //    string strKey = "";
        //    strName = strName.Trim().ToLower();
        //    for (int i = 0; i < arr.Count; i++)
        //    {
        //        if (arr[i] != null)
        //        {
        //            strKey = arr[i].ToString().Trim().ToLower();
        //            if (strKey == strName)
        //            {
        //                return true;
        //            }
        //        }
        //    }
        //    return false;
        //}
        #endregion
    }
}
